import java.util.concurrent.locks.ReentrantLock;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-09-08
 * Time: 16:23
 */
public class demo5 {
    private static int count = 0;

    public static void main(String[] args) throws InterruptedException {
        ReentrantLock locker = new ReentrantLock();
        Thread t1 = new Thread(()->{
            for (int i = 0; i < 5000; i++) {
                locker.lock();
                count++;
                locker.unlock();
            }
        });

        Thread t2 = new Thread(()->{
            for (int i = 0; i < 5000; i++) {
                locker.lock();
                count++;
                locker.unlock();
            }
        });

        t1.start();
        t2.start();
        Thread.sleep(3000);
        System.out.println(count);
    }
}
